package com.jiang.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnectionUtils {

	public static final String DRIVER = "com.mysql.jdbc.Driver";
	public static final String URL = "jdbc:mysql://localhost:3306/newsdb?useSSL=false&&characterEncoding=utf-8";
	public static final String USERNAME="root";
	public static final String PASSWORD="123456";
	private Connection conn = null;
	
	public DBConnectionUtils(){
		try {
			Class.forName(DRIVER);
			conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 获得数据库连接
	 * @return
	 */
	public Connection getConnection(){
		return this.conn;
	}
	
	
	
	public void closeConnection(){
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	
}
